#!/usr/bin/perl

use DBI;
use strict;

my $dsn="dbi:Pg:dbname=flux_monitoring;host=localhost;port=5432";
my $user="postgres";
my $password="";

my $dbh=DBI->connect($dsn,$user,$password,{ RaiseError => 1, AutoCommit => 1});

#my $sth=$dbh->prepare("SELECT * FROM calibrators");

open(CALS,"/DATA/KAPUTAR_1/operations/cals/cats/allmerge.txt");
my $type="p";
my $low_freq=0.0;
my $high_freq=100.0;
while(<CALS>){
    chomp;
    my @els=split(/\s+/);
    my $name=$els[2];
    my $ra=$els[0];
    my $dec=$els[1];
    if ($name ne "1934-638"){
	my $sth=$dbh->prepare("INSERT INTO calibrators VALUES ('$name','$ra','$dec','$type',$low_freq,$high_freq)");
	$sth->execute;
	$sth->finish;
    }
}
close(CALS);

#$sth->execute;

#while (my ($name,$ra,$dec,$type,$low_freq,$high_freq)=$sth->fetchrow()){
#    print "$name $ra $dec\n";
#}

#$sth->finish;

$dbh->disconnect();
